package com.shu.rabbitMq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author ssm
 * @version V1.0
 * @description:
 * @date 2019/4/24 17:28
 */

public class MqInit {
    public static final Logger LOGGER = LoggerFactory.getLogger(MqInit.class);
    // rabbitmq的IP地址
    private static final String RABBITMQ_HOST = "47.98.121.87";
    // rabbitmq的用户名称
    private static final String RABBITMQ_USER = "guest";
    // rabbitmq的用户密码
    private static final String RABBITMQ_PWD = "guest";

    public static final String EXCHANGE_NAME = "direct_logs";
    public static final String QUEUE_NAME = "hello";


    public static Channel channel;
    public static Connection connection;

    // 初始化
    static {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(RABBITMQ_HOST);
        factory.setUsername(RABBITMQ_USER);
        factory.setPassword(RABBITMQ_PWD);
        try {
            connection = factory.newConnection();
            channel = connection.createChannel();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }
    }
}
